package com.stone.bigdata.cron;

import com.stone.bigdata.constant.TimeConstant;
import com.stone.bigdata.utils.RedisUtil;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;

@Component
public class CleanCache extends QuartzJobBean {
    private RedisUtil redisUtil;

    @Autowired
    public CleanCache(RedisUtil redisUtil) {
        this.redisUtil = redisUtil;
    }

    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext)
            throws JobExecutionException {
        System.out.println("开始清除缓存");
        // 任务的具体逻辑
        System.out.println("start job");
        if (redisUtil.hasKey(TimeConstant.NINE)) {
            redisUtil.del(TimeConstant.NINE);
        }
        if (redisUtil.hasKey(TimeConstant.TWELVE)) {
            redisUtil.del(TimeConstant.TWELVE);
        }
        if (redisUtil.hasKey(TimeConstant.FIFTEEN)) {
            redisUtil.del(TimeConstant.FIFTEEN);
        }
        if (redisUtil.hasKey(TimeConstant.EIGHTEEN)) {
            redisUtil.del(TimeConstant.EIGHTEEN);
        }
        if (redisUtil.hasKey(TimeConstant.TWENTY_ONE)) {
            redisUtil.del(TimeConstant.TWENTY_ONE);
        }
    }
}
